{extend name="../../admin/view/main"}

{block name="button"}
<!--{if auth("add")}-->
<button data-open='{:url("add")}' data-title="添加文章" class='layui-btn layui-btn-sm layui-btn-primary'>添加文章</button>
<!--{/if}-->
{/block}

{block name="content"}
<div class="layui-tab">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md2">
            <div class="category_tree think-bg-white">
                <div class="block_title">栏目列表</div>
                <div class="tree_show">
                    <div class="search">
                        <input type="text" id="key" value="" class="layui-input" placeholder="请输入栏目关键字"/>
                    </div>
                    <ul id="categoryTree" class="ztree"></ul>
                </div>
            </div>
        </div>
        <div class="layui-col-md10">
            <div class="article_list think-bg-white">
                {include file='content/index_search'}
                <div class="operator">
                    {if isset($catid)}
                    <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" data-open='{:url("add",["catid"=>$catid])}' data-title="添加文章" >添加</button>
                    <button type="button" class="layui-btn layui-btn-sm">移动</button>
                    {/if}
                    <button type="button" class="layui-btn layui-btn-sm layui-btn-danger">删除</button>
                </div>
                <table class="layui-table margin-top-10" lay-skin="line">
                    {notempty name='list'}
                    <thead>
                    <tr>
                        <th class='list-table-check-td think-checkbox'>
                            <label><input data-auto-none data-check-target='.list-check-box' type='checkbox'></label>
                        </th>
                        <th class='list-table-sort-td'>
                            <button type="button" data-reload class="layui-btn layui-btn-xs">刷 新</button>
                        </th>
                        <th class='text-left nowrap' width="120px">栏目</th>
                        <th class='text-left nowrap' width="120px">文章标题</th>
                        <th class='text-left nowrap' width="150px">缩略图</th>
                        <th class='text-left nowrap'>浏览量</th>
                        <th>状态</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    {/notempty}
                    <tbody>
                    {foreach $list as $key=>$vo}
                    <tr data-dbclick>
                        <td class='list-table-check-td think-checkbox'>
                            <label><input class="list-check-box" value='{$vo.id}' type='checkbox'></label>
                        </td>
                        <td class='list-table-sort-td'>
                            <label><input data-action-blur="{:request()->url()}" data-value="id#{$vo.id};action#sort;sort#{value}" data-loading="false" value="{$vo.sort}" class="list-sort-input"></label>
                        </td>
                        <td class='text-left nowrap'>
                            {$vo.catid}
                        </td>
                        <td class='text-left nowrap'>
                            {$vo.title}
                        </td>
                        <td class='text-left nowrap'>
                            {if $vo.thumb neq ''}
                            <img src="{$vo.thumb}" width="200px"  />
                            {/if}
                        </td>
                        <td class='text-left nowrap'>
                            {$vo.views}
                        </td>
                        <td class='text-left nowrap'>
                            {$vo.status}
                        </td>
                        <td class='text-left nowrap'>
                            {$vo.create_at|format_datetime}
                        </td>
                        <td class='text-left nowrap'>
                            {if isset($type) and $type eq 'all'}
                            <!--{if auth("edit")}-->
                            <a data-dbclick class="layui-btn layui-btn-sm" data-title="编辑文章" data-modal='{:url("edit")}?id={$vo.id}'>编 辑</a>
                            <!--{/if}-->
                            <!--{if auth("remove")}-->
                            <a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="确定要删除此文章吗？" data-action="{:url('remove')}" data-value="id#{$vo.id}" data-csrf="{:systoken('remove')}">删 除</a>
                            <!--{/if}-->
                            {else}
                            <!--{if auth("recover") and $vo.is_deleted eq 1}-->
                            <a class="layui-btn layui-btn-sm layui-btn-warm" data-confirm="确定要恢复该文章吗？" data-action="{:url('recover')}" data-value="id#{$vo.id};is_deleted#0" data-csrf="{:systoken('recover')}">恢 复</a>
                            <!--{/if}-->
                            <!--{if auth("delete")}-->
                            <a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="确定要永久删除此文章吗？" data-action="{:url('delete')}" data-value="id#{$vo.id}" data-csrf="{:systoken('delete')}">永久删除</a>
                            <!--{/if}-->
                            {/if}
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
                {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
            </div>
        </div>
    </div>
</div>
{/block}

{block name='style'}
<link href="__ROOT__/static/plugs/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet">
<script src="__ROOT__/static/plugs/ztree/jquery.ztree.all.js"></script>
<script src="__ROOT__/static/plugs/ztree/jquery.ztree.exhide.js"></script>
<script src="__ROOT__/static/plugs/ztree/fuzzysearch.js"></script>
<style>
    .block_title{
        height: 30px;
        line-height: 30px;
        font-weight: bold;
        font-size: 14px;
        padding: 10px;
        padding-bottom: 0;
        color: #fff;
        background: #009688;
        border-color: #009688;
     }
    .operator{margin-top: 15px;}
    .tree_show{padding: 5px 10px;}
    .category_tree,.article_list{min-height: 650px;}
    .article_list{padding: 0 10px;}
</style>
{/block}

{block name='script'}
<script>
    var zNodes =[
        { id:1, parent_id:0, name:"新闻中心", open:true},
        { id:17, parent_id:0, name:"产品中心"},
        { id:24, parent_id:1, name:"公司新闻"},
        { id:25, parent_id:1, name:"行业资讯"},
        { id:26, parent_id:17, name:"产品类别一"},
        { id:27, parent_id:17, name:"产品类别2"},
    ];
    window.CategoryAction = new function () {
        this.data = {};
        this.ztree = null;
        this.setting = {
            data:{
                simpleData: {
                    enable: true,
                    pIdKey : 'parent_id',
                }
            },
            view: {showLine: true, showIcon: true, dblClickExpand: true},
        };
        this.showTree = function(that, index){
            this.ztree = $.fn.zTree.init($("#categoryTree"), this.setting, this.data);
            fuzzySearch('categoryTree','#key',null,true); //初始化模糊搜索方法
        };
        this.getData = function (that, index) {
            index = $.msg.loading();
            $.form.load('{:url("index")}', {action: 'tree'}, 'get', function (ret) {
                that.data = ret.data;
                return $.msg.close(index), that.showTree(), false;
            });
        };
        this.getData(this);
    }
</script>
{/block}